<?php
//二维数组去掉重复值
function array_unique_fb($array2D){
	foreach ($array2D as $k=>$v){
		$v=join('-',$v);  //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
		$temp[$k]=$v;
	}
	$temp=array_unique($temp); //去掉重复的字符串,也就是重复的一维数组
	foreach ($temp as $k => $v){
		$array=explode('-',$v); //再将拆开的数组重新组装
		//下面的索引根据自己的情况进行修改即可
		$temp2[$k]['uid'] =$array[0];
		$temp2[$k]['name'] =$array[1];
		//$temp2[$k]['keywords'] =$array[2];
		//$temp2[$k]['content'] =$array[3];
	}
	return $temp2;
}

//随机生成字符串
function generate( $length = 6 ) {
	// 密码字符集，可任意添加你需要的字符
	$chars = '0123456789';
	$password ='';
	for ( $i = 0; $i < $length; $i++ )
	{
		$string .= $chars[ mt_rand(0, strlen($chars) - 1) ];
	}
	return $string;
}

//生成随机token码。作为用户登录凭证
function get_token($param=""){
	$token = md5(rand_string());
	$token = md5($token.$param);
	return $token;
}

// 获取随机码
function rand_string($len=6, $type='', $addChars=''){
	$str ='';
	switch($type) {
		case 0:
			$chars='ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789'.$addChars;
			break;
		case 1:
			$chars= str_repeat('0123456789',3);
			break;
		case 2:
			$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ'.$addChars;
			break;
		case 3:
			$chars='abcdefghijklmnopqrstuvwxyz'.$addChars;
			break;
		default :
			// 默认去掉了容易混淆的字符oOLl和数字01，要添加请使用addChars参数
			$chars='ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789'.$addChars;
			break;
	}

	if($len>10 ) {//位数过长重复字符串一定次数
		$chars= $type==1? str_repeat($chars,$len) : str_repeat($chars,5);
	}

	if($type!=4) {
		$chars   =   str_shuffle($chars);
		$str     =   substr($chars,0,$len);

	}else{
		// 中文随机字
		for($i=0;$i<$len;$i++){
			$str.= msubstr($chars, floor(mt_rand(0,mb_strlen($chars,'utf-8')-1)),1);
		}
	}
	return $str;
}

function requestData($url, $post_data, $header) {
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
	if ($post_data) {
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
	}
	if ($header) {
		curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
	}
	$output = curl_exec($ch);
	curl_close($ch);
	return $output;
}



/* //二维数组去掉重复值
function array_unique_fb($array2D){
	foreach ($array2D as $v){
		$v=join('-',$v);  //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
		$temp[]=$v;
	}
	$temp=array_unique($temp);    //去掉重复的字符串,也就是重复的一维数组
	foreach ($temp as $k => $v){
		$temp[$k]=explode('-',$v);   //再将拆开的数组重新组装
	}
	return $temp;
} */
